package systeme;

import java.util.ArrayList;

import rdp.RdP;

public class GrapheRdP {
	public RdP rdp;
	public int nbEtat;
	public int nbTransition;
	public ArrayList<boolean[]> etat = new ArrayList<boolean[]>(); 
	public ArrayList<ArrayList<Integer>> succ = new ArrayList<ArrayList<Integer>>();
	public ArrayList<ArrayList<Integer>> pred = new ArrayList<ArrayList<Integer>>();
	
	public boolean[] recupererEtat(int i){
		
		return etat.get(i);
	}
	
	public ArrayList<Integer> recupererSucc(int etat){
		
		return succ.get(etat);
	}
	
	public ArrayList<Integer> recupererPred(int etat){
		
		return pred.get(etat);
	}
	
	public String toDot(boolean [] b) {
		StringBuffer res = new StringBuffer();
		res.append("digraph system {\n");
		
		if(b[0]){
		res.append("N" + 0 + " [label=\""+rdp.toStringMarquage(etat.get(0)) + "\",shape=octagon color=green]\n");
		
		}else{
			
			res.append("N" + 0 + " [label=\""+rdp.toStringMarquage(etat.get(0)) + "\",shape=octagon]\n");	
		}
		
		for (int e=1; e<etat.size(); e++) {
			if(b[e]){
			res.append("N" + e + " [label=\""+rdp.toStringMarquage(etat.get(e)) + "\",color=green]\n");
			}else{
				res.append("N" + e + " [label=\""+rdp.toStringMarquage(etat.get(e)) + "\"]\n");
			}
			}
		
		for (int e=0;e<etat.size(); e++)
			for (int t=0; t<succ.get(e).size(); t++)
			    res.append("N" + e + " -> N" + succ.get(e).get(t) + "\n"); 
		
		res.append("}\n");
		return res.toString();
	}
	
	public String toDot() {
		StringBuffer res = new StringBuffer();
		res.append("digraph system {\n");
		
		res.append("N" + 0 + " [label=\""+rdp.toStringMarquage(etat.get(0)) + "\",shape=octagon color=green]\n");
				
		for (int e=1; e<etat.size(); e++) {
			res.append("N" + e + " [label=\""+rdp.toStringMarquage(etat.get(e)) + "\"]\n");
		}
		
		for (int e=0;e<etat.size(); e++)
			for (int t=0; t<succ.get(e).size(); t++)
			    res.append("N" + e + " -> N" + succ.get(e).get(t) + "\n"); 
		
		res.append("}\n");
		return res.toString();
	}
}
